/* 
 * File:   ZoomingSelector.cpp
 * Author: Guilherme Monteiro
 * 
 */

#include "../headers/ZoomingSelector.h"

ZoomingSelector::ZoomingSelector(string highResolutionTablePath) throw (NullImageException) {
    try {
        setHighResolutionTable(highResolutionTablePath);
    }
    catch(NullImageException &nie) {
        throw nie;
    }
}

ZoomingSelector::ZoomingSelector(const ZoomingSelector& orig) {
}

ZoomingSelector::~ZoomingSelector() {
}

void ZoomingSelector::setHighResolutionTable(string path) throw (NullImageException) {
    try {
        this->highResolutionTable = cvLoadImage(path.c_str());
    }
    catch(NullImageException &nie) {
        throw nie;
    }
}

/**
 * Executes the zooming selector, identifying
 * the coordinates to apply the zoom in Task3.
 * 
 * @return vector of cells, that represents the selections
 */
vector<Cell> ZoomingSelector::run() {
    vector<Cell> selections;
    
    if(this->highResolutionTable->height > DEFAULT_RESOLUTION_HEIGHT) {
        int h1 = this->highResolutionTable->height/3;
        int h2 = 2 * this->highResolutionTable->height/3;

        Cell* c1 = new Cell(cvPoint(0,0),
                cvPoint(this->highResolutionTable->width, h1 + INTERSECTION_AREA_SIZE));
        Cell* c2 = new Cell(cvPoint(0,h1 - INTERSECTION_AREA_SIZE),
                cvPoint(this->highResolutionTable->width, h2 + INTERSECTION_AREA_SIZE));
        Cell* c3 = new Cell(cvPoint(0,h2 - INTERSECTION_AREA_SIZE),
                cvPoint(this->highResolutionTable->width, this->highResolutionTable->height));

        selections.push_back(*c1);
        selections.push_back(*c2);
        selections.push_back(*c3);
    }
    
    return selections;
}

